package com.qianfeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Attendance;
import com.qianfeng.entity.Department;
import com.qianfeng.mapper.AttendanceMapper;
import com.qianfeng.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class AttendanceServiceImpl implements AttendanceService {

    @Autowired
    private AttendanceMapper attendanceMapper;


    @Override
    public void addAttendance(Attendance attendance) {
        attendanceMapper.addAttendance(attendance);
    }

    @Override
    public void deleteAttendance(Integer attendanceId) {
        attendanceMapper.deleteAttendance(attendanceId);
    }

    @Override
    public void updateAttendance(Attendance attendance) {
        attendanceMapper.updateAttendance(attendance);
    }

    @Override
    public Page getAttendancePage(Integer pageNo, Integer pageSize) {

        PageHelper.startPage(pageNo,pageSize);
        List<Attendance> attendanceList = attendanceMapper.getAttendanceList();

        Page page = new Page();
        PageInfo<Attendance> pageInfo = new PageInfo<>(attendanceList);
        page.setCount(pageInfo.getTotal());
        page.setPages(pageInfo.getPages());
        page.setObj(pageInfo.getList());
        return page;
    }

    @Override
    public List<Attendance> getListByAttendanceId(Integer attendanceId) {
        List<Attendance> list = attendanceMapper.getListByAttendanceId(attendanceId);
        return list;
    }
}
